import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:go_router/go_router.dart';
import 'package:mediapipe_task_vision_example/page/key_test.dart';
import 'package:mediapipe_task_vision_example/page/login.dart';
import 'package:mediapipe_task_vision_example/page/pose_example.dart';
import 'package:mediapipe_task_vision_example/page/pose_live.dart';
import 'package:mediapipe_task_vision_example/page/pose_mlkit.dart';

late List<CameraDescription> cameras;

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setPreferredOrientations([
    //DeviceOrientation.landscapeLeft,
    DeviceOrientation.portraitUp,
  ]);
  cameras = await availableCameras();
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerConfig: _router,
    );
  }
}

final _router = GoRouter(
  routes: [
    GoRoute(
      path: '/',
      builder: (context, state) => const P2PLogin(),
    ),
    GoRoute(
      path: '/controller',
      builder: (context, state) =>
          PoseMlKitWidget(query: state.uri.queryParameters),
    ),
    GoRoute(
      path: '/test',
      builder: (context, state) =>
          KeyTest(ip: state.uri.queryParameters['ip']),
    ),
  ],
);
